package com.borderwaitmaps.client;

import com.borderwaitmaps.client.entities.BorderCrossing;
import com.borderwaitmaps.client.entities.VehicleFlow;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.mapitz.gwt.googleMaps.client.GLatLng;
import com.mapitz.gwt.googleMaps.client.GMarker;
import com.mapitz.gwt.googleMaps.client.GMarkerOptions;

public class BorderCrossingMarker extends GMarker {

	private BorderCrossing borderCrossing;
	private VerticalPanel vp = new VerticalPanel();
	
	public BorderCrossingMarker(
			BorderCrossing borderCrossing, 
			GLatLng point, 
			GMarkerOptions options) {
		
		// init as a GMarker
		super(point, options);
		
		// crossing
		this.borderCrossing = borderCrossing;

		HTML name = new HTML(borderCrossing.getName());
		name.addStyleName("crossing-title");
		vp.add(name);
		
		// lanes with delays
		VehicleFlow commercial = borderCrossing.getCommercialVehicleFlow();
		vp.add(new HTML(VehicleFlow.COMMERCIAL + ": " + commercial.getPrimaryLane().getDelay() + " min"));
		
		VehicleFlow passenger = borderCrossing.getPassengerVehicleFlow();
		vp.add(new HTML(VehicleFlow.PASSENGER + ": " + passenger.getPrimaryLane().getDelay() + " min"));
		
		vp.setStyleName("info-window");
		
		// init the click listener
		initClickListener();

		
	}
	
	private void initClickListener()
	{
		BorderCrossingMarkerEventManager.get().addOnClickListener(this, new BorderCrossingMarkerClickListener());
	}
	
	public void showInfoWindow() {
		this.openInfoWindow(vp);
		BorderWaitMaps.get().getBorderCrossingHistory(borderCrossing);
	}

	public BorderCrossing getBorderCrossing() {
		return borderCrossing;
	}

	public void setBorderCrossing(BorderCrossing borderCrossing) {
		this.borderCrossing = borderCrossing;
	}

}
